package com.neu.af.util;

import java.io.IOException;

public class DBUtil {
    public static void main(String[] args) {
//        String command =
//                "mysqldump --column-statistics=0 -hlocalhost -uroot -p123456 alarmfilter user rule tag monitor_status> C:\\1234\\backupfile.sql";
        String command =
//                "mysql --version";
                "mysql -hlocalhost -uroot -p123456 alarmfilter < C:\\alarm\\backup.sql";
        System.out.println(cmd("cmd.exe /C "+command));
    }

    public static boolean cmd(String command) {
        boolean flag = false;
        try {
            // Process process = Runtime.getRuntime().exec("cmd.exe /C " + command);
            Process process = Runtime.getRuntime().exec(command);
            if (process.waitFor() == 0) {// 0 表示线程正常终止。
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return flag;
    }
}
